class TestResultController < ApplicationController
  
  def stats
    lower_limit = params[:lower_limit]
    higher_limit = params[:higher_limit]
    results = TestResult.select('COUNT(*) as amount, test_id, causeOfFailure_id')
                        .where('build_id BETWEEN ? AND ?',lower_limit,higher_limit)
                        .group('test_id', 'causeOfFailure_id')
    @results = []
    test_results = {}
    last = -1
    results.each do |r|
      if not (test_results.empty? or last == r.test_id)
        @results << test_results = {}
        last = -1
      end
      test_results[r.causeOfFailure_id] = r
      last = r.test_id
    end
  end  
end
